package com.starblink.search.result.repository.model

import android.util.ArrayMap
import com.starblink.rocketreserver.fragment.BrandVOF
import com.starblink.rocketreserver.fragment.PropertyTwoVOF

interface IFrontProperty {
    fun getSelected(): Boolean

    fun setSelected(value: Boolean)
}

data class SelectablePropertyWrap(
    val source: PropertyTwoVOF,
    val properties: List<SelectableProperty> = arrayListOf<SelectableProperty>(),
    var select: Boolean = false,
    val selectCache: ArrayMap<Int, SelectableProperty> = ArrayMap(), // 抽屉中保存的选中状态
    var drawerDataIndex: Int = 0,
    var expand: Boolean = false,
): IFrontProperty {

    fun initCache() {
        selectCache.clear()
        properties.forEachIndexed { index, wrap ->
            if (wrap.selected) {
                selectCache[index] = wrap
            }
        }
    }

    fun loadSelect2Data() {
        properties.forEachIndexed { index, wrap ->
            wrap.selected = selectCache[index] == wrap
        }
    }

    override fun getSelected(): Boolean = select

    override fun setSelected(value: Boolean) {
        select = value
    }


}

data class SelectableProperty(
    val text: String,
    var selected: Boolean, // 真实选中，用于筛选出接口请求
)
data class SelectDiscountProperty(
    var sortType: Int,
)

data class SelectableBrandWrap(
    val brands: List<SelectableBrand> = arrayListOf(),
    var select: Boolean = false,
    val selectCache: ArrayMap<Int, SelectableBrand> = ArrayMap(),
    var hasMoreProperty: Boolean = false,
): IFrontProperty {

    fun initCache() {
        selectCache.clear()
        brands.forEachIndexed { index, wrap ->
            if (wrap.selected) {
                selectCache[index] = wrap
            }
        }
    }

    fun loadSelect2Data() {
        brands.forEachIndexed { index, wrap ->
            wrap.selected = selectCache[index] == wrap
        }
    }

    override fun getSelected(): Boolean = select

    override fun setSelected(value: Boolean) {
        select = value
    }

}

data class SelectableBrand(
    val source: BrandVOF,
    var selected: Boolean
)

data class DrawerTitleModel(
    val text: String,
    var expanded: Boolean? = null,
)

data class DrawerPriceInputModel(
    var min: Double? = null,
    var max: Double? = null,
)
